#!/bin/sh

export LD_LIBRARY_PATH=/thunder/lib
export PATH=$PATH:/thunder/bin

_jsonfile="/thunder/etc/dcdn.json"

# 关闭双矿
offDul() {
	`sed -i 's/\"client_count\": \"2\"/\"client_count\": \"1\"/g' $_jsonfile`
	/sbin/reboot > /dev/null 2>1&
	#/thunder/bin/restart_app.sh > /dev/null 2>1&
}

# 打开双矿
onDul() {
	`sed -i 's/\"client_count\": \"1\"/\"client_count\": \"2\"/g' $_jsonfile`
	/sbin/reboot > /dev/null 2>1&
	#/thunder/bin/restart_app.sh > /dev/null 2>1&
}

# 检测双矿是否运行中，运行返回0，否则返回1
checkStatus() {
	count=`ps | grep dcdn_client | grep -v grep | wc -l`
	if [ ${count} -ne 2 ]; then
		echo "1"
	else
		echo "0"
	fi
}

case "$1" in
  on)
  	_r="$(checkStatus)"
	if [ "$_r" != "0" ]; then
		onDul	
	fi
    ;;
  off)
	_r="$(checkStatus)"
	if [ "$_r" != "1" ]; then
		offDul
	fi
    ;;
  *)
    echo "Usage: dulpro { on | off }" || true
    exit 0
esac

exit 0